Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

427
Visualizações
Django Rest_framework "Got AttributeError when attempting to get a value for field Process"

I have encountered the error which I cannot solve when browsing towards my rest_framework api page.

The full error (Django Error) is :

 Got AttributeError when attempting to get a value for field `process` on   
 serializer `ResultSerializer`.
 The serializer field might be named incorrectly and not match any attribute     
 or key on the `Shop` instance.
 Original exception text was: 'Shop' object has no attribute 'process'.

It seems that the serializer trying to get a value in the field given in another serializer called ResultSerializer but could not found it. I have checked all the fields are all of them are correct.

Here is my models.py

from django.db import models

class ResultSet(models.Model):
    process = models.CharField(max_length=10)
    subprocess = models.CharField(max_length=10)

class Shop(models.Model):
    Establishment = models.CharField(max_length=100)
    Address = models.CharField(max_length=100)
    Suburb = models.CharField(max_length=50)
    Postcode = models.CharField(max_length=10)
    State = models.CharField(max_length=5)
    Establishment_Type = models.CharField(max_length=20)
    latitude = models.DecimalField(decimal_places=6, max_digits=12)
    longtitude = models.DecimalField(decimal_places=6, max_digits=12)
    class Meta:
        ordering = ('Establishment',)

class EntirelyResult(models.Model):
    Result = models.ManyToManyField(Shop, related_name='fullresult')
    Status = models.ManyToManyField(ResultSet, related_name='status')

Here is my serializers.py

from rest_framework.serializers import ModelSerializer
from .models import Shop, ResultSet, EntirelyResult

class ResultSerializer(ModelSerializer):
    class Meta:
        model = ResultSet
        fields = ('process', 'subprocess')

class ShopSerializer(ModelSerializer):
   class Meta:
       model = Shop
       fields = ('__all__')

class ShopDetailSerializer(ModelSerializer):
    Result = ResultSerializer(many=True, read_only=True)
    Status = ShopSerializer(many=True, read_only=True)
    class Meta:
        model = EntirelyResult
        fields = ('Result', 'Status')

Here is my views.py

from rest_framework.generics import ListAPIView
from .models import EntirelyResult
from .serializers import ShopDetailSerializer

class ShopDetailAPIView(ListAPIView):
    queryset = EntirelyResult.objects.all()
    serializer_class = ShopDetailSerializer

Was there anything i miss to make the rest_framework properly?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You got a typo in you serializer ShopDetailSerializer should be:

class ShopDetailSerializer(ModelSerializer):
    Result = ShopSerializer(many=True, read_only=True)
    Status = ResultSerializer(many=True, read_only=True)

Edit: EntirelyResult maps Result field to Shop and Status field to ResultSet while serializer initially mapped Result field to ResultSet and Status field to Shop

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda